package com.ofps.web.controller.flow;

import java.util.Arrays;
import java.util.List;
import javax.servlet.http.HttpServletResponse;

import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ofps.common.annotation.Log;
import com.ofps.common.core.controller.BaseController;
import com.ofps.common.core.domain.AjaxResult;
import com.ofps.common.enums.BusinessType;
import com.ofps.flow.domain.EnterFlowNodeInst;
import com.ofps.flow.service.IEnterFlowNodeInstService;
import com.ofps.common.utils.poi.ExcelUtil;
import com.ofps.common.core.page.TableDataInfo;

/**
 * flowNodeInstanceController
 * flow_node_inst：某个流程的一个实例的节点信息（张三开启某流程后建立，流程执行过程中需要）
 * ● id：流程节点实例的唯一标识
 * ● flow_inst_id：该节点实例隶属的流程实例的id
 * ● order：节点实例在流程内的次序
 * ● last：该节点实例是否为最后一个节点
 * ● related_user_id：关联该节点实例的用户id
 * ● idea：审核该节点的用户的意见
 * ● sign：审核该节点的用户的签名，为base64格式
 * ● status：该节点的状态   0未开始/1审核中/2通过/3退回到该节点，等待员工修改完申请后跳转到/4重新审核
 *
 * @author ofps
 * @date 2022-06-01
 */
@RestController
@RequestMapping("/flowNodeInst")
public class EnterFlowNodeInstController extends BaseController {
    @Autowired
    private IEnterFlowNodeInstService enterFlowNodeInstService;

    /**
     * 查询flow列表
     */
    @PreAuthorize("@ss.hasPermi('flowNodeInst:list')")
    @GetMapping("/list")
    public TableDataInfo list(EnterFlowNodeInst enterFlowNodeInst) {
        startPage();
        List<EnterFlowNodeInst> list = enterFlowNodeInstService.selectEnterFlowNodeInstList(enterFlowNodeInst);
        return getDataTable(list);
    }

    /**
     * 导出flow列表
     */
    @PreAuthorize("@ss.hasPermi('flowNodeInst:export')")
    @Log(title = "flow", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, EnterFlowNodeInst enterFlowNodeInst) {
        List<EnterFlowNodeInst> list = enterFlowNodeInstService.selectEnterFlowNodeInstList(enterFlowNodeInst);
        ExcelUtil<EnterFlowNodeInst> util = new ExcelUtil<EnterFlowNodeInst>(EnterFlowNodeInst.class);
        util.exportExcel(response, list, "flow数据");
    }

    /**
     * 获取flow详细信息
     */
    @PreAuthorize("@ss.hasPermi('flowNodeInst:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") String id) {
        return AjaxResult.success(enterFlowNodeInstService.getById(id));
    }

    /**
     * 新增flow
     */
    @PreAuthorize("@ss.hasPermi('flowNodeInst:add')")
    @Log(title = "flow", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody EnterFlowNodeInst enterFlowNodeInst) {
        return toAjax(enterFlowNodeInstService.save(enterFlowNodeInst));
    }

    /**
     * 修改flow
     */
    @PreAuthorize("@ss.hasPermi('flowNodeInst:edit')")
    @Log(title = "flow", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody EnterFlowNodeInst enterFlowNodeInst) {
        return toAjax(enterFlowNodeInstService.updateById(enterFlowNodeInst));
    }

    /**
     * 删除flow
     */
    @PreAuthorize("@ss.hasPermi('flowNodeInst:remove')")
    @Log(title = "flow", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable String[] ids) {
        return toAjax(enterFlowNodeInstService.removeByIds(Arrays.asList(ids)));
    }
}
